﻿#include "GLLInc.h"
#include "GLLConfig.h"
#include "DBSQLite.h"

namespace GLL
{
	template<typename T, typename TVec>
	TVec Config::GetValue( const char* key )
	{
		TVec vec;
		_pdb->SetFilter(_section, "Key", "Value") = key;
		while(_pdb->LoadRecord())
		{
			T ret = _pdb->Get(0);
			vec.push_back(ret);
		}

		return vec;
	}

	template<typename T>
	T Config::GetValue( const char* key )
	{
		_pdb->SetFilter(_section, "Key", "Value") = key;
		if(!_pdb->LoadRecord()) return T();
		T ret = _pdb->Get(0);
		return ret;
	}

	IntVec Config::GetValueIntVec( const char* key )
	{
		return GetValue<int, IntVec>(key);
	}

	FloatVec Config::GetValueFloatVec( const char* key )
	{
		return GetValue<float, FloatVec>(key);
	}

	StringVec Config::GetValueStrVec( const char* key )
	{
		return GetValue<GLL::String, StringVec>(key);
	}

	int Config::GetValueInt( const char* key )
	{
		return GetValue<int>(key);
	}

	float Config::GetValueFloat( const char* key )
	{
		return GetValue<float>(key);
	}

	String Config::GetValueStr( const char* key )
	{
		return GetValue<String>(key);
	}

	Config::~Config()
	{
		GLL_DEL(_pdb);
	}

	Config::Config( const char* section ) : _section(section)
	{
		_pdb = GLL_NEW DBSQLite("Config");
	}
};//GLL
